package com.longrise.co.ui.mine.model;

import com.google.gson.reflect.TypeToken;
import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.co.api.ApiConstants;
import com.longrise.co.api.ApiService;
import com.longrise.co.ui.mine.contract.MineContract;
import com.ly.common.basebean.BaseResponse;
import com.ly.common.baserx.RxResponseFuncForCar;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by luoyang on 2017-6-23.
 */

public class MineModel implements MineContract.Model {

    @Override
    public Observable<UserInfo> userInfoRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<UserInfo>>(){}.getType(), bean, ApiConstants.APPSEARCHINFO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<UserInfo>());
    }

    @Override
    public Observable<String> modifyUserInfoRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<String>>(){}.getType(), bean, ApiConstants.APPUPDATEUSERINFO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<String>());
    }

    @Override
    public Observable<MineComplaintBean> complaintListRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<MineComplaintBean>>(){}.getType(), bean, ApiConstants.APPSEARCHMYOMPLAIN)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<MineComplaintBean>());
    }

    @Override
    public Observable<MineEvaluationBean> evaluationListRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<MineEvaluationBean>>(){}.getType(), bean, ApiConstants.APPSEARCHEVALUATE)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<MineEvaluationBean>());
    }

    @Override
    public Observable<ComplaintDetailBean> complaintDetailRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<ComplaintDetailBean>>(){}.getType(), bean, ApiConstants.APPGETMYCOMPLAINDETAIL)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<ComplaintDetailBean>());
    }

    @Override
    public Observable<EvaluationDetailBean> evaluationDetailRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<EvaluationDetailBean>>(){}.getType(), bean, ApiConstants.APPEVALUDETAILS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<EvaluationDetailBean>());
    }

    @Override
    public Observable<VerifiedCarBean> verifiedCarRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<VerifiedCarBean>>(){}.getType(), bean, ApiConstants.APPADDCAR)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<VerifiedCarBean>());
    }

    @Override
    public Observable<String> modifyPwdRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<String>>(){}.getType(), bean, ApiConstants.APPUPDATEPASS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<String>());
    }

    @Override
    public Observable<String> deleteCarRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<String>>(){}.getType(), bean, ApiConstants.APPCARDEL)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<String>());
    }

    @Override
    public Observable<EditCarBean> editCarRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<EditCarBean>>(){}.getType(), bean, ApiConstants.APPRECOMMENDDETAILS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<EditCarBean>());
    }

    @Override
    public Observable<Message> messageList(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<Message>>(){}.getType(), bean, ApiConstants.LCIPUSERMESSAGELIST)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<Message>());
    }

    @Override
    public Observable<MessageDetail> messageDetail(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<MessageDetail>>(){}.getType(), bean, ApiConstants.LCIPUSERMESSAGEINFO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<MessageDetail>());
    }
}
